package com.bulletelc.apollopre.module.cases;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.entity.CaseListBean;
import com.bulletelc.apollopre.manager.imageload.ImageLoaderManager;

import java.util.List;

/**
 * Created by Administrator on 2018/5/16.
 */

public class CaseListAdapter extends BaseAdapter {

    private Context context;
    private List<CaseListBean> caseListBeanList;
    private LayoutInflater inflater;

    public CaseListAdapter(Context context, List<CaseListBean> caseListBeanList) {
        this.context = context;
        this.caseListBeanList = caseListBeanList;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return caseListBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return caseListBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        CaseListBean caseListBean = caseListBeanList.get(i);
        ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(R.layout.case_list_item, viewGroup, false);
            viewHolder = new ViewHolder();
            viewHolder.ivCover = view.findViewById(R.id.ivCover);
            viewHolder.tvTitle = view.findViewById(R.id.tvTitle);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tvTitle.setText(caseListBean.getLabel());
        ImageLoaderManager.getInstance().loadImage(ImageLoaderManager.getDefaultOptions(viewHolder.ivCover, caseListBean.getOriginalUrl()));

        return view;
    }


    class ViewHolder {

        private ImageView ivCover;
        private TextView tvTitle;

    }
}
